import { Component, OnInit } from '@angular/core';
import { ActivatedRoute,Params } from '@angular/router';
import { NavController } from '@ionic/angular';
import { ConfigService } from 'src/app/service/config.service';
import { HttpService } from 'src/app/service/http.service';
import { PopwinService } from 'src/app/service/popwin.service';
import { ToolService } from 'src/app/service/tool.service';
import { UrlService } from 'src/app/service/url.service';

@Component({
  selector: 'app-fkdetail',
  templateUrl: './fkdetail.page.html',
  styleUrls: ['./fkdetail.page.scss'],
})
export class FkdetailPage implements OnInit {
  private fID="0";
  public detailData={"content":"","type2":"","m_content":"","ser_content":"","skill_content":""};
  public dateStr:string="";
  public isReplay=false;
  constructor(private navCtrl:NavController,private activatedRoute:ActivatedRoute,private http:HttpService,private popWin:PopwinService) { 
    let that=this;
    this.activatedRoute.queryParams.subscribe((params: Params) => {
      let tempDeal=JSON.parse(ToolService.paramAESDecrypt(params['p']));
      that.fID= tempDeal['fid'];
      that.detailFun();
    });
  }

  ngOnInit() {
     
  }

  detailFun(){
    if(this.fID=='0'){
        this.popWin.toast("非法请求");
        this.backClick();
        return;
    }
    this.fDetailNet(this.fID);
  }

  fDetailNet(fid){
    let that = this;
    let obj = "{\"fee_id\":\"" + fid + "\"}";
    this.http.get(UrlService.OTHER_FEEDBACKDETAIL, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        that.detailData=res;
        if(ToolService.isEmpty(res.m_content) && ToolService.isEmpty(res.ser_content) && ToolService.isEmpty(res.skill_content)){
            that.dateStr=res.created2;
            that.isReplay=false;
        }else{
            that.dateStr=res.updated2;
            that.isReplay=true;
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  

  backClick() {
    this.navCtrl.navigateBack("/fklist");
  }
}
